import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import jsFileDownload from 'js-file-download';

/*引入axios*/
import axios from "axios";
/*引入qs*/
import qs from "qs";
import {MessageBox,Message} from 'element-ui'

import eIconPicker from 'e-icon-picker';
import "e-icon-picker/lib/symbol.js"; //基本彩色图标库
import 'e-icon-picker/lib/index.css'; // 基本样式，包含基本图标
import 'font-awesome/css/font-awesome.min.css'; //font-awesome 图标库
import 'element-ui/lib/theme-chalk/icon.css'; //element-ui 图标库

import *as echarts from 'echarts'//引入echarts
Vue.prototype.$echarts = echarts

//全局删除增加图标
Vue.use(eIconPicker, {
    FontAwesome: true,
    ElementUI: true,
    eIcon: true,//自带的图标，来自阿里妈妈
    eIconSymbol: true,//是否开启彩色图标
    addIconList: [],
    removeIconList: [],
    zIndex: 3100//选择器弹层的最低层,全局配置
});


Vue.prototype.$http = axios
Vue.use(ElementUI)

// 配置axios,qs到Vue
Vue.prototype.axios = axios;
Vue.prototype.qs = qs;
Vue.prototype.jsFileDownload = jsFileDownload;
Vue.config.productionTip = false;

//配置axios拦截请求，添加token头信息
axios.interceptors.request.use(
    config => {
        let token = localStorage.getItem("token");
        console.log("token:" + token);
        if (token) {
            //把localStorage的token放在Authorization里
            config.headers.Authorization = token;
        }
        return config;
    },
    function(err) {
        console.log("失败信息" + err);
    }
);

//错误响应拦截
axios.interceptors.response.use(res => {
    console.log('拦截响应');
    if( res.data.data === '验证错误，需要登录' ){
        console.log('验证错误，需要登录')
        // window.location.href = '/'
        MessageBox.alert('没有权限,需要登录','权限错误',{
            confirmButtonText:'跳转登录页面',
            callback: action => {
                window.location.href = '/'
            }
        })
    }

    if (res.data.status === 'OK' || res.status === 200) {
        return res;
    }
})
Vue.config.productionTip = false

new Vue({
    router,
    render: function (h) { return h(App) }
}).$mount('#app')
